<?php

namespace Home\Model;
use Think\Model;

class CommonModel extends Model
{   

    /**
     * 查询分类商品Model类
     * @param number $[id] [<导航分级id>]
     * @return [type] [返回所有符合条件且状态为1的商品id]
     * @author Weiliqiang <[<email address>]>
     */
    public function queryGoods($id)
    {
        $flag = D('classify')->where("pid={$id}")->select();
        if($flag){
            $res = D('classify')->where("path like '%,{$id},%'")->field('id')->select();
            foreach($res as $v){
                $str .= $v['id'].',';
            }
            $res = rtrim($str,',');
            $goods = D('goods')->field('goods_id')->where("classify_id in ({$res}) and status=1")->select();
        }else{
            $goods = D('goods')->field('goods_id')->where("classify_id = {$id} and status=1")->select();
        }
        $goods_id = '';
        foreach($goods as $v){
            $goods_id .= $v['goods_id'].',';
        }
        return $goods_id = rtrim($goods_id,',');
    }

}
